package com.wangsir.util;

import java.util.List;

public class PagerVO<T> {
    //当前页面
    private Integer currentPage;
    //一页多少行数据
    private Integer pageSize;
    //一共有多少数据
    private Integer totalSize;
    //用来存储数据
    private List<T> list;
    //一共多少页面
    private Integer totalPage;
    //左边是否还有页面
    private boolean showLeft;
    //右边是否还有页面
    private boolean showRight;
    //用来存储页面的页码
    private int[] pageNums;

    public PagerVO(Integer currentPage, Integer pageSize, Integer totalSize, List<T> list, Integer totalPage, boolean showLeft, boolean showRight, int[] pageNums) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalSize = totalSize;
        this.list = list;
        this.totalPage = totalPage;
        this.showLeft = showLeft;
        this.showRight = showRight;
        this.pageNums = pageNums;
    }
    //单元测试
    public static void main(String[] args) {
        PagerVO<Object> objectPagerVO = new PagerVO<>();
        objectPagerVO.setCurrentPage(4);
        objectPagerVO.setPageSize(10);
        objectPagerVO.setTotalSize(104);
        objectPagerVO.init();
        System.out.println(objectPagerVO.getTotalPage());
        for (int i = 0; i < objectPagerVO.getPageNums().length; i++) {
            int[] pageNums1 = objectPagerVO.getPageNums();
            System.out.print(pageNums1[i] + " ");
        }
    }
    //初始化页码
    public void init(){
        totalPage  = totalSize / pageSize;
        if(totalSize % pageSize > 0){
            totalPage ++;
        }
        if(currentPage == 1){
            showLeft = false;
        }else{
            showLeft = true;
        }
        if(currentPage == totalPage){
            showRight = false;
        }else{
            showRight = true;
        }
        //计算最先页码和最大的页码
        int min = currentPage - 5;
        int max = currentPage + 5;
        if(min < 1){
            min = 1;
        }
        if(max > totalSize){
            max = totalPage;
        }
        int length = max - min + 1;
        pageNums = new int[length];
        for (int i = 0; i < length; i++) {
            pageNums[i] = min + i;
        }
    }

    public PagerVO() {
    }

    public PagerVO(Integer currentPage, Integer pageSize, Integer totalSize, List<T> list) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalSize = totalSize;
        this.list = list;
    }


    /**
     * 获取
     * @return currentPage
     */
    public Integer getCurrentPage() {
        return currentPage;
    }

    /**
     * 设置
     * @param currentPage
     */
    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    /**
     * 获取
     * @return pageSize
     */
    public Integer getPageSize() {
        return pageSize;
    }

    /**
     * 设置
     * @param pageSize
     */
    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * 获取
     * @return totalSize
     */
    public Integer getTotalSize() {
        return totalSize;
    }

    /**
     * 设置
     * @param totalSize
     */
    public void setTotalSize(Integer totalSize) {
        this.totalSize = totalSize;
    }

    /**
     * 获取
     * @return list
     */
    public List<T> getList() {
        return list;
    }

    /**
     * 设置
     * @param list
     */
    public void setList(List<T> list) {
        this.list = list;
    }

    public String toString() {
        return "PagerVO{currentPage = " + currentPage + ", pageSize = " + pageSize + ", totalSize = " + totalSize + ", list = " + list + "}";
    }

    /**
     * 获取
     * @return totalPage
     */
    public Integer getTotalPage() {
        return totalPage;
    }

    /**
     * 设置
     * @param totalPage
     */
    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    /**
     * 获取
     * @return showLeft
     */
    public boolean isShowLeft() {
        return showLeft;
    }

    /**
     * 设置
     * @param showLeft
     */
    public void setShowLeft(boolean showLeft) {
        this.showLeft = showLeft;
    }

    /**
     * 获取
     * @return showRight
     */
    public boolean isShowRight() {
        return showRight;
    }

    /**
     * 设置
     * @param showRight
     */
    public void setShowRight(boolean showRight) {
        this.showRight = showRight;
    }

    /**
     * 获取
     * @return pageNums
     */
    public int[] getPageNums() {
        return pageNums;
    }

    /**
     * 设置
     * @param pageNums
     */
    public void setPageNums(int[] pageNums) {
        this.pageNums = pageNums;
    }
}
